package cn.edu.cug.cs.gtl.docsrv;

import cn.edu.cug.cs.gtl.docsrv.config.Configuration;
import cn.edu.cug.cs.gtl.docsrv.config.FTPConfig;
import cn.edu.cug.cs.gtl.docsrv.config.HDFSConfig;
import cn.edu.cug.cs.gtl.docsrv.config.ManagerConfig;
import cn.edu.cug.cs.gtl.docsrv.img.manager.ImgManager;
import cn.edu.cug.cs.gtl.docsrv.raw.manager.LocalRawManager;
//import cn.edu.cug.cs.gtl.docsrv.raw.manager.OracleRawManager;
import cn.edu.cug.cs.gtl.docsrv.raw.manager.RawManager;
import cn.edu.cug.cs.gtl.docsrv.shp.manager.*;
import cn.edu.cug.cs.gtl.docsrv.txt.TxtManager;
import cn.edu.cug.cs.gtl.net.ftp.client.ClientFTP;
import cn.edu.cug.cs.gtl.net.hdfs.client.ClientHDFS;

public class Managers {

    public static ShpManager getShpManager() {
        try{
            ManagerConfig managerConfig = Configuration.getManagerConfig();
            switch (managerConfig.getShpManagerType()){

                case "rdb1":{//关系数据库，单表模式
                    ShpManager shpManager = new RDBShpManagerForSingleTable(Configuration.getMasterSession());
                    return shpManager;
                }
                case "hdfs":{//关系数据库+HDFS
                    HDFSConfig hdfsConfig = Configuration.getHdfsConfig();
                    ShpManager shpManager = new HDFSShpManager(Configuration.getMasterSession(),
                            ClientHDFS.of(hdfsConfig.getHdfsIP(),
                                    Integer.valueOf(hdfsConfig.getHdfsIP()),
                                    hdfsConfig.getHdfsCurrentDirectory()) );

                    return shpManager;
                }
                case "ftp":{//关系数据库+FTP
                    FTPConfig ftpConfig = Configuration.getFtpConfig();
                    ShpManager shpManager = new FTPShpManager(
                            Configuration.getMasterSession(),
                            ClientFTP.of(ftpConfig.getFtpIP(),
                                    ftpConfig.getFtpPort(), ftpConfig.getFtpUser(),ftpConfig.getFtpPassword(),
                                    ftpConfig.getFtpWorkingDirectory(),ftpConfig.getFtpType()));
                    return shpManager;
                }
                case "sdb":{//空间数据库
                    ShpManager shpManager = new SDBShpManager(Configuration.getMasterSession());
                    return shpManager;
                }
                case "mdb":{//内存数据库
                    return null;
                }
                case "rdb2":{//关系数据库，双表模式
                    ShpManager shpManager = new RDBShpManager(Configuration.getMasterSession());
                    return shpManager;
                }
                default:{//本地文件，SQLITE+LocalFileSystem
                    ShpManager shpManager = new LocalShpManager(Configuration.getMasterSession());
                    return shpManager;
                }
            }

        }
        catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }


    public static ImgManager getImgManager() {
        try{
            ManagerConfig managerConfig = Configuration.getManagerConfig();
            switch (managerConfig.getImgManagerType()){

                case "rdb1":{//关系数据库，单表模式
                    return null;
                }
                case "hdfs":{//关系数据库+HDFS
                    return null;
                }
                case "ftp":{//关系数据库+FTP
                    return null;
                }
                case "sdb":{//空间数据库
                    return null;
                }
                case "mdb":{//内存数据库
                    return null;
                }
                case "rdb2":{//关系数据库，双表模式
                    return null;
                }
                default:{//本地文件，SQLITE+LocalFileSystem
                    return null;
                }
            }

        }
        catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public static TxtManager getTxtManager() {
        return null;
    }

    public static RawManager getRawManager() {
        try{
            RawManager rawManager = new LocalRawManager(Configuration.getMasterSession());
            return rawManager;
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

}
